/*
 * @Author: xiaosihan
 * @Date: 2024-07-30 18:22:46
 * @Last Modified by: xiaosihan
 * @Last Modified time: 2024-09-17 16:57:12
 */

import { PartAttachment, PartData } from "../type";
import Api from "./Api";

// 零件库的 接口
class PartsApi extends Api {
  constructor() {
    super();
  }

  // 获取模型类型id
  getModelType() {
    return this._post("/customer/modelType/list");
  }
  //添加零件
  add(
    typeId: string,
    name: string,
    url: string,
    thumbnailUrl: string,
    size: string,
    projectId: string
  ) {
    return this._post("/customer/model/add", {
      typeId,
      name,
      url,
      thumbnailUrl,
      size,
      projectId,
    });
  }
  //添加零件的附件
  addAttachment(param: {
    modelId: string;
    name: string;
    url: string;
    size: string;
  }) {
    return this._post("/customer/attachment/add", param);
  }
  //删除零件的附件
  deleteAttachment(id: string) {
    return this._post(`/customer/attachment/delete?id=${id}`);
  }
  // 更新零件的附件
  updataAttachment(param: Partial<PartAttachment> & { id: string }) {
    return this._post(`/customer/attachment/update`, param);
  }
  //修改零件
  update(partData: Partial<PartData>) {
    return this._post("/customer/model/add", { partData });
  }
  //删除零件
  delete(id: string) {
    return this._post(`/customer/model/delete?id=${id}`);
  }
  //查询零件
  get_list(pageNum: number, pageSize: number, data: any) {
    return this._post("/customer/model/list", {
      pageNum,
      pageSize,
      data,
    });
  }
  //获取单个零件的信息
  get_part_info(id: string = "") {
    return this._post(`/customer/model/get?id=${id}`);
  }
  //获取新的分享的的token
  getShareToken(modelId: string) {
    return this._post(
      `/customer/modelShareLink/getShareLink?modelId=${modelId}`
    );
  }
  //校验token
  verificationToken(token: string = "") {
    return this._post(`/customer/modelShareLink/add?shareToken=${token}`);
  }
  //删除分享
  deleteShare(modelId: string) {
    return this._post(`/customer/modelShareLink/delete?id=${modelId}`);
  }
  //打开分享链接
  getShare(modelId: string) {
    return this._post(
      `/customer/modelShareLink/getByModelId?modelId=${modelId}`
    );
  }
}

const partsApi = new PartsApi();

export default partsApi;
